/* */

// request a username check from ajax
function check_username()
{
	username = document.getElementById('username');
	if(username.value != '' && username.value.length >= 3 && username.value.length <= 20) {
		// we have a valid username
		ajax_http_request('index.php?what=login&do=check_username&username='+username.value, 'process_username');
	} else {
		stat = document.getElementById('username_status');
		stat.style.display = 'block';
		stat.innerHTML = '<span class="invalid">A username must be between 3-20 characters long and only contain alphanumeric characters.</span>';
		username.select();
	}
}

// process the data from the check username ajax call
function process_username(status)
{
	console.log(status);
	stat		= document.getElementById('username_status');
	username	= document.getElementById('username');

	stat.style.display = 'block';

	switch(status) {
		case 'false':
			stat.innerHTML = '<span class="available">Username Available</span>';
			break;
		case 'true':
			stat.innerHTML = '<span class="taken">Username taken</span>';
			username.select();
			break;
		case 'invalid':
			stat.innerHTML = '<span class="invalid">A username must be between 3-20 characters long and only contain alphanumeric characters.</span>';
			username.select();
			break;
	}
}